package vn.game;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.Transformation;
import android.widget.Gallery;

public class MyGallery extends Gallery {

	String tag = MyGallery.class.getSimpleName();

	public MyGallery(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public MyGallery(Context context) {
		super(context);
//		setPadding(5, 0, 5, 0);
	}

	@Override
	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
		int kEvent;
		if (isScrollingLeft(e1, e2)) { // Check if scrolling left
			kEvent = KeyEvent.KEYCODE_DPAD_LEFT;
			Log.i(tag, "pad left");
		} else { // Otherwise scrolling right
			kEvent = KeyEvent.KEYCODE_DPAD_RIGHT;
			Log.i(tag, "pad right");
		}
		onKeyDown(kEvent, null);
		return true;
	}

	@Override
	protected boolean getChildStaticTransformation(View child, Transformation t) {
//		Log.i(tag,"getChildStaticTransformation()");
		return false;

	}

	@Override
	protected void onSizeChanged(int w, int h, int oldw, int oldh) {
		Log.i(tag, "size changed");
		super.onSizeChanged(w, h, oldw, oldh);
	}
	
//	@Override
//	  public boolean dispatchTouchEvent(MotionEvent ev) {
//	    
//	    if (ev.getAction() == MotionEvent.ACTION_MOVE) {
//	    	Log.i(tag,"dispatchTouchEvent action move");
//	    }
//	    else
//	    	Log.i(tag,"dispatchTouchEvent else");
//	    return super.dispatchTouchEvent(ev);
//	  }

	@Override
	  public void onLongPress(MotionEvent event) {
    	Log.i(tag,"onLongPress");
	  // Your long-press handler...
	    super.onLongPress(event);
	  }



	private boolean isScrollingLeft(MotionEvent e1, MotionEvent e2) {
		return e2.getX() > e1.getX();
	}

	@Override
	public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
//		Log.i(tag,"onScroll...");
		return super.onScroll(e1, e2, distanceX, distanceY);
	}
}
